package com.web.servlet;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by Alige on 2016/5/27.
 */
public class JspPageSessionCheckFilter implements Filter {


    private  String  defaultUrl ="/";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {


    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {


        /**
         *  解决 jsp 资源管理问题
         */
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        String serverPath = request.getContextPath();


        try {
            response.sendRedirect(serverPath + defaultUrl);
            filterChain.doFilter(servletRequest, servletResponse);
        }catch (Exception e){
              e.printStackTrace();
        }
    }

    @Override
    public void destroy() {

    }




}
